package com.zzyl.controller.security;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeptDto;
import com.zzyl.dto.ResourceDto;
import com.zzyl.service.ResourceService;
import com.zzyl.vo.MenuVo;
import com.zzyl.vo.ResourceVo;
import com.zzyl.vo.TreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/resource")
@Api(tags = "资源管理")
public class ResourceController {

    @Autowired
    private ResourceService resourceService;

    @ApiOperation("资源列表")
    @PostMapping("/list")
    public ResponseResult<List<ResourceVo>> resourceList(@RequestBody ResourceDto dto) {
        log.info("资源列表");
        List<ResourceVo> resourceVos = resourceService.resourceList(dto);
        return ResponseResult.success(resourceVos);

    }


    @ApiOperation("资源树形")
    @PostMapping("/tree")
    public ResponseResult<TreeVo> resourceTree(@RequestBody ResourceDto dto) {
        log.info("资源树形:{}", dto);
        TreeVo treeVo = resourceService.resourceTree(dto);
        return ResponseResult.success(treeVo);
    }

    @ApiOperation("资源添加")
    @PutMapping
    public ResponseResult<Void> addResource(@RequestBody ResourceDto dto) {
        log.info("资源添加:{}", dto);
        resourceService.addResource(dto);
        return ResponseResult.success();
    }


    @PatchMapping
    @ApiOperation(value = "部门修改", notes = "部门修改")
    public ResponseResult<Void> updateResource(@RequestBody ResourceDto dto) {
        resourceService.updateResource(dto);
        return ResponseResult.success();
    }




    @ApiOperation("启用禁用")
    @PostMapping("enable")
    public ResponseResult<Void> enable(@RequestBody ResourceDto dto) {
        log.info("启用禁用:{}", dto);
        resourceService.enable(dto);
        return ResponseResult.success();
    }



    @ApiOperation("删除菜单")
    @DeleteMapping("{menuId}")
    public ResponseResult<Void> remove(@PathVariable Long menuId) {
        log.info("删除菜单:{}", menuId);
        resourceService.remove(menuId);
        return ResponseResult.success();
    }

    ////////////////////////////////////////////////////////////////////////////////////

    @GetMapping("/menus")
    @ApiOperation("我的菜单")
    public ResponseResult<List<MenuVo>> getMyMenus() {
        log.info("我的菜单");
        List<MenuVo> menus = resourceService.getMyMenus();
        return ResponseResult.success(menus);
    }
}
